package com.bl.student.manager.controller.notice;

import com.bl.student.manager.controller.BaseController;
import com.bl.student.common.ApiResponseBody;
import com.bl.student.dao.model.NoticeEntity;
import com.bl.student.service.biz.notice.NoticeService;
import com.bl.student.service.vo.goods.GoodsAddVo;
import com.bl.student.service.vo.notice.NoticeAddVo;
import com.bl.student.service.vo.tag.TagListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * Created by yujingyi on 2018/1/29.
 */
@RestController
@Log4j2
@RequestMapping(value = {"/student/manager/notice"})
@Api(value = "通知", description = "通知")
public class NoticeController extends BaseController {
    @Autowired
    NoticeService noticeService;

    @ApiOperation(value = "增加通知", notes = "增加通知 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/add"})
    public ApiResponseBody add(
            @Valid @RequestBody NoticeAddVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        noticeService.add(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "通知", notes = "通知")
    @ApiImplicitParams({})
    @GetMapping(value = {"/get"})
    public ApiResponseBody<TagListVo> list(
            HttpServletRequest request) {

        NoticeEntity noticeEntity = noticeService.getNotice();

        return ApiResponseBody.createSuccessBody(noticeEntity);
    }


}
